<template>
  <!--
      	作者：luoyiming
      	时间：2020-06-01
      	描述：审核弹窗
      -->
  <div>
    <el-dialog
      :title="title"
      width="600px"
      :visible.sync="dialogVisible"
      @close="dialogFormVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="auditform">
        <el-form-item label="审核状态" :label-width="formLabelWidth">
          <div>
            <el-radio v-model="audit_status" label="1">通过</el-radio>
            <el-radio v-model="audit_status" label="2">不通过</el-radio>
          </div>
        </el-form-item>
        <div v-if="audit_status == 2">
          <el-form-item label="不通过原因" :label-width="formLabelWidth">
            <el-input v-model="auditform.remark" autocomplete="off"></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible(false)">取 消</el-button>
        <el-button type="primary" @click="auditSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      audit_status: "1",
      remark: "",
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false
    };
  },
  props: ["open_audit", "auditform", "title", "ids", "AuditApi", "pk"],
  created() {
    this.dialogVisible = this.open_audit;
    if (this.auditform.audit_status) {
      this.audit_status = this.auditform.audit_status.toString();
    }
    this.remark = this.auditform.remark;
  },
  methods: {
    /*审核*/
    auditSubmit() {
      let self = this;
      let params = this.auditform;
      this.AuditApi.auditStatusSubmit(
        {
          [this.pk]: this.ids.length > 0 ? this.ids : params[this.pk],
          audit_status: this.audit_status,
          remark: params.remark
        },
        true
      )
        .then(data => {
          self.$message({
            message: "恭喜你，操作成功",
            type: "success"
          });
          self.dialogFormVisible(true);
        })
        .catch(error => {});
    },

    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("closeDialog", {
          type: "success",
          openDialog: false
        });
      } else {
        this.$emit("closeDialog", {
          type: "error",
          openDialog: false
        });
      }
    }
  }
};
</script>

<style></style>
